package com.cancan.cloud.shop.controller;

import com.cancan.cloud.shop.domain.Product;
import com.cancan.cloud.shop.feign.ProductFeignApi;
import com.cancan.cloud.shop.service.IProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductFeignClient implements ProductFeignApi {
    @Autowired
    private IProductService productService;

    @Value("${server.port}")
    private String port;

    @Override
    public Product find(Long id) {
        Product product = productService.get(id);
        Product result = new Product();
        BeanUtils.copyProperties(product,result);
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        result.setName(result.getName()+",data from "+port);
        return result;
    }
}